//package com.ai.chat.config;
//
//import com.ai.chat.module.order.constant.WeChatPayUrl;
//import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
//import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
//import org.apache.http.client.HttpClient;
//import org.apache.http.client.config.RequestConfig;
//import org.apache.http.config.Registry;
//import org.apache.http.config.RegistryBuilder;
//import org.apache.http.conn.socket.ConnectionSocketFactory;
//import org.apache.http.conn.socket.PlainConnectionSocketFactory;
//import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
//import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.client.ClientHttpRequestFactory;
//import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
//import org.springframework.web.client.RestTemplate;
//
//import java.io.ByteArrayInputStream;
//import java.nio.charset.StandardCharsets;
//import java.security.cert.X509Certificate;
//import java.util.ArrayList;
//import java.util.List;
//
//
///**
// * @author: MrHe
// * @create: 2024-02-06 00:56
// * @description:
// **/
//@Configuration
//public class WeRestTemplateChatConfig {
//
//
//    @Bean("weChatRestTemplate1")
//    public RestTemplate weChatRestTemplate(){
//        return new RestTemplate(httpRequestFactory());
//    }
//    @Bean
//    public ClientHttpRequestFactory httpRequestFactory() {
//        return new HttpComponentsClientHttpRequestFactory(httpClient());
//    }
//
//
//    @Bean
//    public HttpClient httpClient() {
//        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
//                .register("http", PlainConnectionSocketFactory.getSocketFactory())
//                .register("https", SSLConnectionSocketFactory.getSocketFactory())
//                .build();
//        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
//        connectionManager.setMaxTotal(3000);
//        connectionManager.setDefaultMaxPerRoute(1000);
//
//        RequestConfig requestConfig = RequestConfig.custom()
//                .setSocketTimeout(5000)
//                .setConnectTimeout(5000)
//                .setConnectionRequestTimeout(5000)
//                .build();
//        X509Certificate wechatPayCertificate = PemUtil.loadCertificate(
//                new ByteArrayInputStream(WeChatPayUrl.WX_CERT.getBytes(StandardCharsets.UTF_8)));
//
//        List<X509Certificate> listCertificates = new ArrayList<>();
//        listCertificates.add(wechatPayCertificate);
//
//        WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
//                .withMerchant(WeChatPayUrl.MCH_ID, WeChatPayUrl.MCH_SERIAL_NO, PemUtil.loadPrivateKey(WeChatPayUrl.API_CLIENT_KEY))
//                .withWechatPay(listCertificates);
//
//        return builder
//                .setDefaultRequestConfig(requestConfig)
//                .setConnectionManager(connectionManager)
//                .build();
//    }
//
//
//}
